package com.etc.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.etc.entity.Seller;
import com.etc.service.SellerService;

@Controller
//@RequestMapping(value = "")
public class SellerController {

	@Resource
	private SellerService ss;


	/**
	 * 
	 * @return
	 */
	@RequestMapping(value = "/seller", method = RequestMethod.GET)
	public ModelAndView showSellers() {
		ModelAndView mv = new ModelAndView("seller-list_admin");
				List<Seller> list = ss.showSellers();
				mv.addObject("list", list);
				return mv;
	}


	/**
	 * 根据商家Id修改审核状态
	 * @param sellerId
	 * @param sState
	 * @return
	 */
   @RequestMapping(value="upState")
   public ModelAndView upState(int sellerId,int sState,HttpServletRequest request) {
	   ModelAndView mv = new ModelAndView("seller-list_admin");
	   int str=Integer.valueOf(request.getParameter("sState"));
	   if(str==0) {
		   str=1;
	   }
	   else if(str==1) {
		   str=0;
	   }
	  boolean flag = ss.upState(sellerId, str);
	   
	   if(flag) {
		   
		   List<Seller> list = ss.showSellers();
		   mv.addObject("list", list); 
	   }
	   
	   return mv;
	   
   }

   /**
    * 删除单个
    * @param sellerId
    * @return
    */
    @RequestMapping(value = "/delseller/{sellerId}", method = RequestMethod.DELETE)
	@ResponseBody
	public boolean delSeller(@PathVariable("sellerId") int sellerId) {

	
		boolean flag = ss.delseller(sellerId);

		return flag;// 测试值
	}
    
	@RequestMapping(value = "/sellerLogin/{storeTel}", method = RequestMethod.GET)
	@ResponseBody
	public Seller sellerLogin(@PathVariable(value="storeTel") String storeTel) {

				return ss.loginByTel(storeTel);
	}


	
	


}
